﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;
using System.Web.Security;
using Tebbee.UI.Client.AccountSer;
using Tebbee.UI.Client.ExchangeSer;
using Tebbee.UI.Client.ProductSer;

namespace Tebbee.UI.Client.Controllers.MemberApi
{
    public class MemberProductController : ApiController
    {
        private readonly ProductSerClient db = new ProductSerClient();
        private readonly AccountSerClient dblogin = new AccountSerClient();
        private readonly ExchangeSerClient exDb = new ExchangeSerClient();
        public IEnumerable<Product> GetProducts()
        {
            var tmp = db.AllProducts();
            return tmp;
        }

        public Product GetProductById(int id)
        {
            var pro = db.GetProductById(id);
            return pro;
        }

        public HttpResponseMessage PostProduct(List<MemberExchangeLog> OrderListToSave)
        {
            if (ModelState.IsValid)
            {
                exDb.AddNewShoppingCart(OrderListToSave);
                return Request.CreateResponse(HttpStatusCode.Created, OrderListToSave);
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
    }
}
